package com.itheima.algorithm.datastructure;

/**
 * 删除链表中重复的元素
 */
public class Leetcode83 {

    public static ListNode deleteDuplicates(ListNode head){
        // 节点数<2
        if(head ==null || head.next == null){
            return head;
        }
        //节点数>=2
        ListNode p1 = head;
        ListNode p2 = p1.next;
        while (p2!=null){
            if(p1.value == p2.value){
                //删除p2
                p1.next = p2.next;
            }else{
                //向后平移
                p1 = p1.next;
            }
            p2 = p1.next;

        }
        return head;
    }

    public static void main(String[] args) {
        ListNode head = ListNode.of(1,1,2,3,3);
        System.out.println(head);
        System.out.println(deleteDuplicates(head));
    }
}
